<template>
  <div class="tabs">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="全部" name="all">
        <div class="my_ipt">
          <a-input
            placeholder="请输入任务"
            class="inp"
            :value="inputValue"
            @change="inputChange"
            @keyup.enter="addItems"
          />
          <a-button type="primary" @click="addItems">添加</a-button>
        </div>

        <a-list bordered :dataSource="todoList" class="dt_list">
          <a-list-item slot="renderItem" slot-scope="item">
            <!-- 复选框 -->
            <a-checkbox
              :checked="item.done === '1'"
              @change="
                (e) => {
                  cbChange(e, item);
                }
              "
              >{{ item.content }}</a-checkbox
            >
            <!-- 删除链接 -->
            <a slot="actions" @click.prevent="removeItems(item.tId)">删除</a>
          </a-list-item>

          <!-- footer区域 -->
          <div slot="footer" class="footer">
            <!-- 未完成的任务个数 -->
            <span>{{ selectSurplus }} 条剩余</span>
            <!-- <a href="#">清空已完成</a> -->
          </div>
        </a-list>
      </el-tab-pane>
      <el-tab-pane label="已完成" name="done">
        <div class="my_ipt">
          <a-input
            placeholder="请输入任务"
            class="inp"
            :value="inputValue"
            @change="inputChange"
            @keyup.enter="addItems"
          />
          <a-button type="primary" @click="addItems">添加</a-button>
          <a-button type="primary" @click="exportData">导出</a-button>
        </div>

        <a-list bordered :dataSource="selectDone" class="dt_list">
          <a-list-item slot="renderItem" slot-scope="item">
            <!-- 复选框 -->
            <a-checkbox
              :checked="item.done === '1'"
              @change="
                (e) => {
                  cbChange(e, item);
                }
              "
              >{{ item.content }}</a-checkbox
            >
            <!-- 删除链接 -->
            <a slot="actions" @click.prevent="removeItems(item.tId)">删除</a>
          </a-list-item>

          <!-- footer区域 -->
          <div slot="footer" class="footer">
            <!-- 未完成的任务个数 -->
            <span>{{ selectSurplus }} 条剩余</span>
            <!-- <a href="#">清空已完成</a> -->
          </div>
        </a-list>
      </el-tab-pane>
      <el-tab-pane label="未完成" name="undone">
        <div class="my_ipt">
          <el-row>
            <el-col :xs="24" :sm="24" :lg="20">
              <a-input
                placeholder="请输入任务"
                class="inp"
                :value="inputValue"
                @change="inputChange"
                @keyup.enter="addItems"
              />
            </el-col>
            <el-col :xs="24" :sm="24" :lg="4">
              <a-button type="primary" @click="addItems">添加</a-button>
            </el-col>
          </el-row>
        </div>

        <a-list bordered :dataSource="selectUnDone" class="dt_list">
          <a-list-item slot="renderItem" slot-scope="item">
            <!-- 复选框 -->
            <a-checkbox
              :checked="item.done === '1'"
              @change="
                (e) => {
                  cbChange(e, item);
                }
              "
              >{{ item.content }}</a-checkbox
            >
            <!-- 删除链接 -->
            <a slot="actions" @click.prevent="removeItems(item.tId)">删除</a>
          </a-list-item>

          <!-- footer区域 -->
          <div slot="footer" class="footer">
            <!-- 未完成的任务个数 -->
            <span>{{ selectSurplus }} 条剩余</span>
            <!-- <a href="#">清空已完成</a> -->
          </div>
        </a-list>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { mapState, mapActions, mapGetters } from "vuex";
import { getDate } from "@/utils/index";
import { exportData } from "@/api/system/todo";
export default {
  components: {},
  data() {
    return {
      activeName: "all", // tabs控件
    };
  },
  watch: {
    activeName: "changeBar",
  },
  computed: {
    ...mapState("todo", ["inputValue", "todoList", "targetTime"]),
    ...mapGetters(["todoList"]),
    ...mapGetters("todo", ["selectDone", "selectUnDone", "selectSurplus"]),
  },
  mounted() {
    this.getList(getDate());
  },
  created() {},
  destroyed() {},
  methods: {
    ...mapActions("todo", [
      "update_value",
      "addItem",
      "getList",
      "changeStatus",
      "removeItem",
    ]),

    // 捕捉tab点击事件
    handleClick(tab) {
      console.log(tab);
    },
    // 复选框点击事件
    cbChange(e, obj) {
      this.changeStatus(obj);
    },
    // 文本框更改事件
    inputChange(e) {
      this.update_value(e.target.value);
    },

    // tab更改事件, 不用，使用上面的elementui 提供的handleClick方法捕捉
    changeBar(curVal, oldVal) {
      console.log(curVal + " -> " + oldVal);
    },

    // 添加 item 项
    addItems() {
      this.addItem();
    },
    // 删除item项
    removeItems(arg) {
      this.removeItem(arg);
    },

    // 数据导出
    exportData() {
      exportData();
    },
  },
};
</script>

<style scoped lang="scss">
.v-enter,
.v-leave-to {
  /* 进入时候动画 */
  opacity: 0;
  transform: translateY(80px);
}

.v-enter-active,
.v-leave-active {
  transition: all 0.8s ease;
}

/*.v-move和v-leave-active合起来实现 删除时的渐渐离开的效果**/
.v-move {
  transition: all 0.8s ease;
}

.v-leave-active {
  position: absolute;
}
.tabs {
  float: left;
  width: 100%;
}

.my_ipt {
  //   width: 500px;
  width: 100%;
  margin-right: 10px;
  .inp {
    width: 85%;
  }
  button {
    margin-left: 10px;
  }
}

.dt_list {
  //   width: 500px;
  //   max-height: 400px;
  width: 100%;
  margin-top: 10px;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>